
export const HOOKS = [
  'beforeCreate',
  'created',
  'beforeMount',
  'mounted',
  'beforeUpdate',
  'updated',
  'beforeDestroy',
  'destroyed',
  'activated',
  'deactivated',
  'errorCaptured',
  'serverPrefetch',
  'renderTracked',
  'renderTriggered',
  'watch'
]
// 合并方法
// 策略模式
let strats = {}
strats.data = function(parentVal,childVal){
  return childVal
}
strats.component = function(parentVal,childVal){
  // return childVal
  const obj = Object.create(parentVal)
  if(childVal){
    for (const key in childVal) {
      obj[key] = childVal[key]
    }
  }
  return obj
}
// strats.watch = function(){}
// strats.methods = function(){}
// // strats.created = function(){}
// HOOKS.forEach(hook => {
//   strats[hook] = mergeHook
// })
function mergeHook(parentVal,childVal){
  if(childVal){
    if(parentVal){
      return parentVal.concat(childVal)
    }else{
      return [childVal]
    }
  }else{
    return parentVal
  }
}
// 遍历生命周期
/**
 * Helper that recursively merges two data objects together.
 */
export function mergeOptions(parent,child){
  const options = []
  let key
  // 有父亲没儿子
  for (key in parent) {
    mergeField(key)
  }
  // 有儿子没父亲
  for (key in child) {
    // if (!hasOwn(parent, key)) {
      mergeField(key)
    // }
  }
  // 策略模式
  function mergeField(key) {
    // console.log('[ key ] >', parent,key)
    if (strats[key]) {
      // 传了2个参数进去
      options[key] = strats[key](parent[key],child[key])
    }else{
      options[key] = child[key] || parent[key]
    }
    // options[key] = strat(parent[key], child[key], vm, key)
  }
  return options
}
const defaultStrat = function (parentVal, childVal){
  return childVal === undefined ? parentVal : childVal
}
